import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import fire_component_msg from '@feidao/web/atom/browser/msg/fire';
import excel_json from '../../atom-web/excel-json';
import error from '@feidao/web/atom/browser/msgbox/error';
import success from '@feidao/web/atom/browser/msgbox/success';
import get from '@feidao/web/atom/browser/local/get';
export default async function a003(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	//导入
	const input = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="import_excel"]');
	const file = input.files[0];
	const dom = args[0].currentTarget
	console.log('------->>>', dom)
	const stw = dom.getAttribute('data-feidao-switch');
	const ag = get(fd, 'args');
	if (stw == 'false') {   //判断开关状态
		success('正在保存中！');
		return
	}
	dom.setAttribute('data-feidao-switch', 'false');
	if (!file) {
		dom.setAttribute('data-feidao-switch', 'true');
		error('请选择excel文件！');
		return;
	}
	const reader = new FileReader();
	reader.onload = async function (e) {
		console.log(ag['id'], ag['event_name'], { str: excel_json(reader.result as any), dom });
		fire_component_msg(ag['id'], ag['event_name'], { str: excel_json(reader.result as any), dom });
		dom.setAttribute('data-feidao-switch', 'true');
	};
	reader.readAsArrayBuffer(file);
}
